package loggeri.android.namespace;

import java.util.ArrayList;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

public class View implements OnClickListener{
	
	private static int paiva = 0;
	private ChainHandler ch;
	private CheckBoxHandler cbh;
	private LinearLayout ll,paivienlayout,ketjunlayout;
	private ScrollView sv;
	private GridView gv;
	
	public View(Activity activity) {
		
		sv = new ScrollView(activity);
		//gv = new GridView(activity);
		ll = new LinearLayout(activity);
        ll.setOrientation(LinearLayout.HORIZONTAL);
        //ll.setPadding(15, 30,15,80);
        
        paivienlayout = new LinearLayout(activity);
		paivienlayout.setOrientation(LinearLayout.VERTICAL);
		paivienlayout.setPadding(15,15,15,15);
		
		//paivienlayout.setGravity(Gravity.CENTER);
		((ViewGroup) ll).addView(paivienlayout);
        sv.addView(ll);
        cbh = new CheckBoxHandler();
		/*ll = new LinearLayout(activity);
        ll.setOrientation(LinearLayout.VERTICAL);
        
        horizontal.addView(ll);*/
        
	}
	
	public void rekChainHandler(ChainHandler ch) {
		this.ch = ch;
	}
	
	public void ketjuNakyma(Activity activity) {
		ArrayList<Chain> ketjut = ch.ketjut();
		Chain c = ketjut.get(ketjut.size()-1);
		
		//for(Chain c : ketjut) {
			//ketjunlayout = new LinearLayout(activity);
			//ketjunlayout.setOrientation(LinearLayout.VERTICAL);
			TextView tv = new TextView(activity);
			//cb = new CheckBox(activity);
	        tv.setText(c.getName().toString());
	        c.getLl().addView(tv);
	        
	        //ketju.tulostaNodet(activity);

	        
	        

	        c.getLl().addView(cbh.makeCheckBox(activity, c));
	        ll.addView(c.getLl());
		//}

		
	}
	
	public void paivaNakymat(Activity activity) {
		
		TextView tv = new TextView(activity);
		TextView tyhjio = new TextView(activity);
		
		
		tv.setText(ch.generoiPaiva(paiva));
		paiva++;
		paivienlayout.addView(tyhjio);
	
		paivienlayout.addView(tv);
		ArrayList<Chain> ketjut = ch.ketjut();
		
		for(Chain c : ketjut) {

			c.getLl().addView(cbh.makeCheckBox(activity, c));

		}
		//
	}

	public LinearLayout getLl() {
		return ll;
	}

	public void setLl(LinearLayout ll) {
		this.ll = ll;
	}

	public ScrollView getSv() {
		return sv;
	}

	public void setSv(ScrollView sv) {
		this.sv = sv;
	}

	
	public GridView getGv() {
		return gv;
	}

	public void setGv(GridView gv) {
		this.gv = gv;
	}

	@Override
	public void onClick(DialogInterface dialog, int which) {
		
		
	}
	
	
}
